package com.sss.controller;

import com.sss.model.Doctor;
import com.sss.model.DoctorVO;
import com.sss.service.DoctorService;
import com.sss.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.print.Doc;
import java.util.HashMap;
import java.util.List;

/**
 * 全世界我最爱朴彩英！
 *
 * @Author sss
 * @Create 2023/12/1 20:40
 * @desc
 */
@RestController
public class DoctorController {

    @Autowired
    private DoctorService service;

    //通过id查找
    @GetMapping("/by/id")
    public R findById(int id){
        Doctor doctor = service.findById(id);
        return R.ok(doctor);
    }

    //无条件查全部
    @GetMapping("/all")
    public R findAll(){
        List<Doctor> list = service.findAll();
        return R.ok(list);
    }

    //有条件查全部
    @GetMapping("/partFind")
    public R partFind(String name,int hip){
        Doctor doctor =service.partFind(name,hip);
        return R.ok(doctor);
    }

    //通过Map查询
    @GetMapping("/map")
    public R ByMapFind(@RequestParam HashMap<String,Object> map){
        Doctor doctor = service.ByMapFind(map);
        return R.ok(doctor);
    }

    //更新
    @GetMapping("/update")
    public R updateDoc(Doctor doctor){
        int i = service.updateDoc(doctor);
        if (i>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }


    //注册
    @GetMapping("/add")
    public R register(Doctor doctor){
        int i = service.register(doctor);
        if (i>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    //删除
    @GetMapping("/del?=5")
    public R deleteDoc(int id){
        System.out.println(id);
        int i = service.deleteDoc(id);
        if (i>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }


    //多表联查(一对一)
    @GetMapping("/one")
    public R one2one(int id){
        DoctorVO doctorVO = service.DocWithHosById(id);
        return R.ok(doctorVO);
    }

}
